#!/usr/bin/env ruby

#
# Get platform (code from Matt Mower <self@mattmower.com>)
#
if RUBY_PLATFORM =~ /darwin/i
	OS = :unix
	IMPL = :macosx
elsif RUBY_PLATFORM =~ /linux/i
	OS = :unix
	IMPL = :linux
elsif RUBY_PLATFORM =~ /freebsd/i
	OS = :unix
	IMPL = :freebsd
elsif RUBY_PLATFORM =~ /netbsd/i
	OS = :unix
	IMPL = :netbsd
elsif RUBY_PLATFORM =~ /mswin/i
	OS = :win32
	IMPL = :mswin
elsif RUBY_PLATFORM =~ /cygwin/i
	OS = :unix
	IMPL = :cygwin
elsif RUBY_PLATFORM =~ /mingw/i
	OS = :win32
	IMPL = :mingw
elsif RUBY_PLATFORM =~ /bccwin/i
	OS = :win32
	IMPL = :bccwin
elsif RUBY_PLATFORM =~ /wince/i
	OS = :win32
	IMPL = :wince
elsif RUBY_PLATFORM =~ /vms/i
	OS = :vms
	IMPL = :vms
elsif RUBY_PLATFORM =~ /os2/i
	OS = :os2
	IMPL = :os2 # maybe there is some better choice here?
elsif RUBY_PLATFORM =~ /solaris/i # tnx to Hugh Sasse
	OS = :unix
	IMPL = :solaris
elsif RUBY_PLATFORM =~ /irix/i # i.e. mips-irix6.5
	OS = :unix
	IMPL = :irix
else
	OS = :unknown
	IMPL = :unknown
end
if OS == :win32
	DIR = '.'
	HOME = ENV['HOME'] || ENV['HOMEDRIVE'] + ENV['HOMEPATH'] || ENV['USERPROFILE'] 
else
	DIR = '/usr/local/share/bookwrite'
	HOME = ENV['HOME']
end

begin
	require 'gtk2'
rescue LoadError
	puts 'You don\'t seem to have the RubyGnome 2 libraries in your system.'
	puts 'They are available at <http://ruby-gnome2.sourceforge.jp/>'
	exit -1
end

if Gtk::BUILD_VERSION[0] < 2 or Gtk::BUILD_VERSION[1] < 10
	puts "You need your Gtk+ to be at least version 2.10"
	exit -1
end

begin
	require 'yaml'
rescue LoadError
	m = Gtk::MessageDialog.new(nil, 0, Gtk::MessageDialog::ERROR, Gtk::MessageDialog::BUTTONS_OK, 'Ruby-YAML not found.')
	m.secondary_text = 'Ruby-YAML libraries were not found in your system. You can get them at <http://yaml4r.sourceforge.net/>.'
	m.run
	m.destroy
	exit -1
end

begin
	require 'iconv'
	$has_iconv = true
rescue LoadError
	$has_iconv = false
end

$: << "#{DIR}/src"
$: << "#{DIR}/src/book"

require 'i18n'
load_language

require 'book'

require 'tips'
require 'chapterlist'
require 'menubutton'
require 'new_book'
require 'export_book'
require 'main'
require 'conf'
require 'text'
require 'configurations'
require 'export'
require 'help'

Gtk.init
begin
	Gtk::Window.default_icon_list = [Gdk::Pixbuf.new("#{DIR}/src/icon_16.png"), Gdk::Pixbuf.new("#{DIR}/src/icon_24.png")]
rescue; end
$conf = Conf.load
$main = Main.new
Gtk.main
